<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/3/7
 * Time: 11:06
 */

namespace app\models;

use yii;
use yii\db\Query;

class InvoiceLock extends BaseModel
{
    public function __construct()
    {
        $this->table = yii::$app->db->tablePrefix . 'invoice_lock';
    }

    public function all($where = [], $offset = false, $limit = false, $order = false)
    {
        $db = new Query();
        $db->select('*')->from($this->table);
        if (!empty($where['invoice_id'])) {
            if (is_array($where['invoice_id'])) {
                $db->andWhere(['in', 'invoice_id', $where['invoice_id']]);
            } else {
                $db->andWhere(['invoice_id' => $where['invoice_id']]);
            }
        }
        return $db->all();
    }

    public function one($where = [])
    {
        $db = new Query();
        $db->select('*')->from($this->table);
        if (!empty($where['invoice_id'])) {
            $db->andWhere(['invoice_id' => $where['invoice_id']]);
        }

        return $db->limit(1)->one();

    }

}
